home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / dev / lang / python_src.lha / amigapython / parser / intrcheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-17  |  3.8 KB  |  196 lines

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI not be used in advertising or publicity pertaining to
  13. distribution of the software without specific, written prior permission.
  14.  
  15. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  18. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  21. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* Check for interrupts */
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30.  
  31. #include "myproto.h"
  32. #include "intrcheck.h"
  33.  
  34. #ifdef QUICKWIN
  35.  
  36. #include <io.h>
  37.  
  38. void
  39. initintr()
  40. {
  41. }
  42.  
  43. int
  44. intrcheck()
  45. {
  46.     _wyield();
  47. }
  48.  
  49. #define OK
  50.  
  51. #endif /* QUICKWIN */
  52.  
  53. #ifdef _M_IX86
  54. #include <io.h>
  55. #endif
  56.  
  57. #if defined(MSDOS) && !defined(QUICKWIN)
  58.  
  59. #ifdef __GNUC__
  60.  
  61. /* This is for DJGPP's GO32 extender.  I don't know how to trap
  62.  * control-C  (There's no API for ctrl-C, and I don't want to mess with
  63.  * the interrupt vectors.)  However, this DOES catch control-break.
  64.  * --Amrit
  65.  */
  66.  
  67. #include <go32.h>
  68.  
  69. void
  70. initintr()
  71. {
  72.     _go32_want_ctrl_break(1 /* TRUE */);
  73. }
  74.  
  75. int
  76. intrcheck()
  77. {
  78.     return _go32_was_ctrl_break_hit();
  79. }
  80.  
  81. #else /* !__GNUC__ */
  82.  
  83. /* This might work for MS-DOS (untested though): */
  84.  
  85. void
  86. initintr()
  87. {
  88. }
  89.  
  90. int
  91. intrcheck()
  92. {
  93.     int interrupted = 0;
  94.     while (kbhit()) {
  95.         if (getch() == '\003')
  96.             interrupted = 1;
  97.     }
  98.     return interrupted;
  99. }
  100.  
  101. #endif /* __GNUC__ */
  102.  
  103. #define OK
  104.  
  105. #endif /* MSDOS && !QUICKWIN */
  106.  
  107.  
  108. #ifdef macintosh
  109.  
  110. /* The Mac interrupt code has moved to macglue.c */
  111. #define OK
  112.  
  113. #endif /* macintosh */
  114.  
  115.  
  116. #ifndef OK
  117.  
  118. /* Default version -- for real operating systems and for Standard C */
  119.  
  120. #include <stdio.h>
  121. #include <string.h>
  122. #include <signal.h>
  123.  
  124. static int interrupted;
  125.  
  126. #ifdef AMIGA
  127. #include <dos.h>
  128. void __regargs _CXBRK(void);
  129. void __regargs _CXBRK(void) {
  130.     interrupted = 1;
  131. }
  132. #endif
  133.  
  134. void
  135. PyErr_SetInterrupt()
  136. {
  137.     interrupted = 1;
  138. }
  139.  
  140. /* ARGSUSED */
  141. static RETSIGTYPE
  142. #ifdef _M_IX86
  143. intcatcher(int sig)    /* So the C compiler shuts up */
  144. #else /* _M_IX86 */
  145. intcatcher(sig)
  146.     int sig; /* Not used by required by interface */
  147. #endif /* _M_IX86 */
  148. {
  149.     extern void goaway PROTO((int));
  150.     static char message[] =
  151. "python: to interrupt a truly hanging Python program, interrupt once more.\n";
  152.  
  153.     switch (interrupted++) {
  154.     case 0:
  155.         break;
  156.     case 1:
  157.         write(2, message, strlen(message));
  158.         break;
  159.     case 2:
  160.         interrupted = 0;
  161.         goaway(1);
  162.         break;
  163.     }
  164.     signal(SIGINT, intcatcher);
  165. }
  166.  
  167. void
  168. initintr()
  169. {
  170.     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  171.         signal(SIGINT, intcatcher);
  172. #ifdef HAVE_SIGINTERRUPT
  173.     /* This is for SunOS and other modern BSD derivatives.
  174.        It means that system calls (like read()) are not restarted
  175.        after an interrupt.  This is necessary so interrupting a
  176.        read() or readline() call works as expected.
  177.        XXX On old BSD (pure 4.2 or older) you may have to do this
  178.        differently! */
  179.     siginterrupt(SIGINT, 1);
  180. #endif /* HAVE_SIGINTERRUPT */
  181. }
  182.  
  183. int
  184. intrcheck()
  185. {
  186. #ifdef AMIGA
  187.     chkabort(); // Explicit check for Ctrl/C which calls _CXBRK(void);
  188. #endif
  189.     if (!interrupted)
  190.         return 0;
  191.     interrupted = 0;
  192.     return 1;
  193. }
  194.  
  195. #endif /* !OK */
  196.